﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DotNet.Core.Entity;
using DotNet.Core.Service;
using DotNet.Helper;
using DotNet.Utility;
using DotNet.Extensions;
using DotNet.JCore.Service;
using DotNet.JCore.Entity;
using DotNet.Auth.Utility;
using DotNet.Web.Areas.AuthWeb.Controllers;

namespace DotNet.Web.Areas.Mobile.Controllers
{
    public class SyncCarExitStationController : AuthController
    {
        private SyncCarExitStationService service = new SyncCarExitStationService();

        public ActionResult Index()
        {
            //var currentUser = AuthHelper.GetSessionUser();
            //if (!currentUser.IsAdmin)
            //{
            //    ViewBag.pointId = CurrentEmployee.PointId;

            //}
            return View();
        }

        private ActionResult NotFound(string id)
        {
            return NotFound("获取 同步车辆出站数据信息 错误", $"无法找到 主键 = {id} 的同步车辆出站数据信息");
        }


        /// <summary>
        /// 获取当天未稽查数据列表
        /// </summary>
        /// <param name="CarNO">车牌号</param>
        /// <param name="Point">稽查点</param>
        /// <param name="Station">客运站</param>
        /// <param name="Time">时间段：单位（分钟）</param>
        /// <returns></returns>
        //public ActionResult Grid(string CarNO)
        //{
        //    var list = service.GetList(CarNO);
        //    return View(list);
        //}

        public ActionResult Edit(string id)
        {
            var entity = service.Get(id);
            entity.CheckStatus = 1;
            entity.ProcessStatus = false;
            entity.Note = "系统违规登记";
            if (entity == null) return NotFound(id);
            return EditCore(entity);
        }

        private ActionResult EditCore(SyncCarExitStationModel entity)
        {
            return View("Edit", entity);
        }

        public ActionResult Details(string id)
        {
            var entity = service.Get(id);
            if (entity == null) return NotFound(id);
            return View(entity);
        }



        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Save(SyncCarExitStationModel entity)
        {
            //entity.PoinID = CurrentEmployee.PointId;
            //entity.PointName = CurrentEmployee.PointName;
            AuthHelper.SetJCUserInfo(entity, true);
            var result = service.Save(entity, true);
            return Json(result);
        }

        public ActionResult Confirm(string id)
        {
            var entity = service.Get(id);

            entity.CheckStatus = 0;
            entity.ProcessStatus = true;
            entity.Note = "系统正常登记";
            AuthHelper.SetJCUserInfo(entity, true);
            if (entity == null) return NotFound(id);
            return View("Confirm", entity);
        }
    }
}